<script setup>

import {onMounted, ref} from "vue";
import {ElMessage} from "element-plus";
import http from "@/request/Http.js";


const userMessage = ref([])

//===========设置基本信息================
const queryParams = ref({
  token: '',
})
// 获取对象信息
const getUserMessage = async () => {
  let urlSearchParams = new URLSearchParams(queryParams.value)
  const data = await http.get("/user/userMessage?" + urlSearchParams.toString())
  //获取值并把值赋给userMessage
  console.log(data.data)
  userMessage.value = data.data
  console.log(userMessage)
}

onMounted(async () => {
  await getUserMessage()
})

//点击保存save
const save = async () => {//获取表单数据
  const data = await http.post('/user/updateById', userMessage.value)
  if (data.code === 200) {
    ElMessage.success("成功保存")
  }
}

</script>

<template>
  <el-row>
    <el-form :data="userMessage">
      <el-form-item v-if="false" label="id" prop="id">
        <el-input v-model="userMessage.id"/>
      </el-form-item>
      <el-form-item label="用户名" prop="username">
        <el-input v-model="userMessage.username" :disabled="true"/>
      </el-form-item>
      <el-form-item label="联系电话" prop="phone">
        <el-input v-model="userMessage.phone"/>
      </el-form-item>
      <el-form-item label="邮箱地址" prop="email">
        <el-input v-model="userMessage.email"/>
      </el-form-item>
      <el-form-item label="真实姓名" prop="realname">
        <el-input v-model="userMessage.realname"/>
      </el-form-item>
      <el-form-item label="身份证号码" prop="id_card">
        <el-input v-model="userMessage.id_card"/>
      </el-form-item>

      <!--  保存和关闭按钮-->
      <el-form-item>
        <el-button class="change-button" type="primary" @click="save">保存</el-button>
        <el-button type="warning">取消</el-button>
      </el-form-item>
    </el-form>
  </el-row>
</template>

<style scoped>

</style>